Total Complexity | 2 |
Total Lines | 31 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 0 |
1 | import Twit from 'twit'; |
||
16 | |||
17 | export default class Bot { |
||
18 | twit: Twit; |
||
19 | config: BotConfig; |
||
20 | debug: Debug.Debugger; |
||
21 | |||
22 | constructor(config: BotConfig) { |
||
23 | this.twit = new Twit(config.apiConfig); |
||
24 | this.config = config; |
||
25 | this.debug = Helper.objectExists(config.debugNamespace) && config.debugNamespace ? Debug(config.debugNamespace) : Debug(Constant.DEBUGGER_DEFAULT_NAMESPACE); |
||
26 | } |
||
27 | |||
28 | async retweet(searchParams: Twit.Params): Promise<void> { |
||
29 | const like = new Like(this.config, this.twit, this.debug); |
||
30 | const likeOnSuccess = async(tweet: Tweet) => await like.run({ |
||
31 | tweet |
||
32 | }); |
||
33 | |||
34 | const retweet = new Retweet(this.config, this.twit, this.debug); |
||
35 | const retweetOnSuccess = async(tweet: Tweet) => await retweet.run({ |
||
36 | tweet, |
||
37 | onSuccess: likeOnSuccess |
||
38 | }); |
||
39 | |||
40 | const search = new Search(this.config, this.twit, this.debug); |
||
41 | await search.run({ |
||
42 | searchParams, |
||
43 | onSuccess: retweetOnSuccess |
||
44 | }); |
||
45 | |||
46 | this.debug('All done.'); |
||
47 | } |
||
48 | } |